<?php

/**
 * BlogComment form.
 *
 * @package    HugoHamon
 * @subpackage form
 * @author     Hugo Hamon <hugo.hamon@sensio.com>
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class BlogCommentForm extends BaseBlogCommentForm
{
  public function configure()
  {
    $this->widgetSchema['follow_by_email'] = new sfWidgetFormInputCheckbox();
    $this->validatorSchema['follow_by_email'] = new sfValidatorBoolean(array('required' => false));

    $fields = array(
      'name', 'email',
      'source_content',
      'follow_by_email'
    );

    $this->useFields($fields, true);
  }
  
  protected function doSave($con = null)
  {
    parent::doSave($con);
    
    $post  = $this->getObject()->getPost();
    $email = $this->getObject()->getEmail();
    
    if ($this->getValue('follow_by_email') && !$post->hasSubscriber($email))
    {
      $post->subscribe($email, $this->getOption('culture'));
    }
  }
}
